function estimates=estimate_wrapper(config_id,config,input)

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % INITIALIZE
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

reps=config.reps;
warning('off', 'NAG:warning');

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % MAIN RUN
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

[theta]=estimate(config_id,config,input);

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % BOOTSTRAP
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

theta_star=NaN*ones(size(theta,1),reps);
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % FIRST: FOR LOOP 
    % -- RUNS IN PARALLEL --
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                           
parfor rr=1:reps,

    warning('off', 'NAG:warning');
    data_bootstrap=prepare_data_bootstrap(config);
    config_bootstrap=initialize_config(data_bootstrap, input,config_id);
    theta_star(:,rr)=estimate(config_id,config_bootstrap,input);

    if isnan(theta_star(:,rr))==0,
        fprintf('.');
    else
        fprintf('-');    
    end;

end;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % SECOND: WHILE LOOP
    % -- CHECK FOR MISSING ENTRIES --
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     
rr=1;
count=1;
count_max=reps+50;

while (rr<=reps) && (count<=count_max),
    
    if isnan(theta_star(:,rr))==1,

            fprintf('Run %6.2f needs re-run\n',rr);
                
            data_bootstrap=prepare_data_bootstrap(config);
            config_bootstrap=initialize_config(config_id, data_bootstrap, input);
            theta_star(:,rr)=estimate(config_id,config_bootstrap,input);
        
            if isnan(theta_star(:,rr))==0,
                rr=rr+1;
                fprintf('.');
            else
                fprintf('-');    
            end;
        
            count=count+1;

    else

            rr=rr+1;
            count=count+1;

    end;
                
end;

fprintf('\n');

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % OUTPUT
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

estimates.theta=theta;
estimates.theta_star=theta_star;
    
    %
